<?php 
namespace Admin\Controller;
use Admin\Api\AlipayNotifyApi;
use Common\Api\AccountApi;
use Common\Api\ApiCallHisApi;
use Common\Model\ApiCallHisModel;
use Shop\Api\InviteRankingApi;
use Think\Controller;


class QueryTableInfoController extends AdminController{
	
	public function index(){

		$table=I("tableName","");
        $filter = I('post.filter','');
		$dbName='tables_in_'.C('DB_NAME');
		$db = M();
		$dbs=$db->query($sql = 'show tables');
		for ($i=0; $i <count($dbs); $i++) { 
			$tables[]=$dbs[$i][$dbName];
		}
		if($table==""){
			$table=$tables[0];
		}
		$result=$db->query("select * from ".$table.' LIMIT 0,1');
		$keys=array();
		if(count($result)!=0){
			$keys=array_keys($result[0]);
            if(empty($filter)){
                $result=$db->query("select * from ".$table." order by ".$keys[0]." desc  LIMIT 0,50");
		    }else{
                $result=$db->query("select * from ".$table." where ".$filter." order by ".$keys[0]." desc  LIMIT 0,50");
            }

        }

        $this->assign('filter',$filter);
		$this->assign('listKey',$keys);
		$this->assign('tableArray',$tables);
		$this->assign('list',$result);
		$this->assign('tableName',$table);
		$this->display();
	}
	
	
	
	public function login(){
		$this->display();
	}


	public function test(){
		dump($this->getMonDay());
		dump($this->getSunDay());
	}


	public function getMonDay(){
		$w=(int)date('w',time());
		$t=($w-1)*24*3600;
		return strtotime(date('Y-m-d',time()-$t));
	}

	public function getSunDay(){
		$w=(int)date('w',time());
		$t=(8-$w)*24*3600-1;
		return strtotime(date('Y-m-d',time()+$t))-1;
	}

    public function testzjport(){
        $filter = I('param.filter','');

        $map = array(
            'api_uri'=>array('like','ZjportCallback%'),

        );

        if(!empty($filter)){
            $map['api_uri'] = array('like',$filter);
        }

        $page = array('curpage'=>I('param.p',0),'size'=>10);

        $order = "id desc";
        $result = apiCall(ApiCallHisApi::QUERY,array($map,$page,$order));



        $this->assign('filter',$filter);
        $this->assign('show',$result['info']['show']);
        $this->assign('list',$result['info']['list']);
        $this->display();
    }

}
